unit dbschemaDBDAO;
interface
uses
  AdoDB, Forms, windows, db, sysutils, AbstractDAO, dbschema_AbstractModel;
type
  TtablesDAO = class(TAbstractDBDAO)
  private
    FTableName: string;
  protected
    procedure SetTableName(value: string);
  public
    function DoInsert(value: TAbstractModel; q1: TDataSet): Boolean; override;
    function DoUpdate(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoDelete(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoSelect(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoGetValue(value: TAbstractModel; q1: TDataSet): Boolean; override;
    function SetValue(value: TAbstractModel; q1: TDataSet): Boolean; override;
  published
    property TableName: string read FTableName write SetTableName;
  end;
  TcolumnsDAO = class(TAbstractDBDAO)
  private
    FTableName: string;
  protected
    procedure SetTableName(value: string);
  public
    function DoInsert(value: TAbstractModel; q1: TDataSet): Boolean; override;
    function DoUpdate(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoDelete(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoSelect(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoGetValue(value: TAbstractModel; q1: TDataSet): Boolean; override;
    function SetValue(value: TAbstractModel; q1: TDataSet): Boolean; override;
  published
    property TableName: string read FTableName write SetTableName;
  end;
  TindexesDAO = class(TAbstractDBDAO)
  private
    FTableName: string;
  protected
    procedure SetTableName(value: string);
  public
    function DoInsert(value: TAbstractModel; q1: TDataSet): Boolean; override;
    function DoUpdate(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoDelete(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoSelect(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoGetValue(value: TAbstractModel; q1: TDataSet): Boolean; override;
    function SetValue(value: TAbstractModel; q1: TDataSet): Boolean; override;
  published
    property TableName: string read FTableName write SetTableName;
  end;
  TfrKeysDAO = class(TAbstractDBDAO)
  private
    FTableName: string;
  protected
    procedure SetTableName(value: string);
  public
    function DoInsert(value: TAbstractModel; q1: TDataSet): Boolean; override;
    function DoUpdate(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoDelete(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoSelect(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoGetValue(value: TAbstractModel; q1: TDataSet): Boolean; override;
    function SetValue(value: TAbstractModel; q1: TDataSet): Boolean; override;
  published
    property TableName: string read FTableName write SetTableName;
  end;
  TsystypesxDAO = class(TAbstractDBDAO)
  private
    FTableName: string;
  protected
    procedure SetTableName(value: string);
  public
    function DoInsert(value: TAbstractModel; q1: TDataSet): Boolean; override;
    function DoUpdate(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoDelete(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoSelect(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoGetValue(value: TAbstractModel; q1: TDataSet): Boolean; override;
    function SetValue(value: TAbstractModel; q1: TDataSet): Boolean; override;
  published
    property TableName: string read FTableName write SetTableName;
  end;
  TusertypesDAO = class(TAbstractDBDAO)
  private
    FTableName: string;
  protected
    procedure SetTableName(value: string);
  public
    function DoInsert(value: TAbstractModel; q1: TDataSet): Boolean; override;
    function DoUpdate(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoDelete(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoSelect(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoGetValue(value: TAbstractModel; q1: TDataSet): Boolean; override;
    function SetValue(value: TAbstractModel; q1: TDataSet): Boolean; override;
  published
    property TableName: string read FTableName write SetTableName;
  end;
  TdefaultsDAO = class(TAbstractDBDAO)
  private
    FTableName: string;
  protected
    procedure SetTableName(value: string);
  public
    function DoInsert(value: TAbstractModel; q1: TDataSet): Boolean; override;
    function DoUpdate(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoDelete(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoSelect(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoGetValue(value: TAbstractModel; q1: TDataSet): Boolean; override;
    function SetValue(value: TAbstractModel; q1: TDataSet): Boolean; override;
  published
    property TableName: string read FTableName write SetTableName;
  end;
  TtrigersDAO = class(TAbstractDBDAO)
  private
    FTableName: string;
  protected
    procedure SetTableName(value: string);
  public
    function DoInsert(value: TAbstractModel; q1: TDataSet): Boolean; override;
    function DoUpdate(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoDelete(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoSelect(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoGetValue(value: TAbstractModel; q1: TDataSet): Boolean; override;
    function SetValue(value: TAbstractModel; q1: TDataSet): Boolean; override;
  published
    property TableName: string read FTableName write SetTableName;
  end;
  TviewsDAO = class(TAbstractDBDAO)
  private
    FTableName: string;
  protected
    procedure SetTableName(value: string);
  public
    function DoInsert(value: TAbstractModel; q1: TDataSet): Boolean; override;
    function DoUpdate(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoDelete(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoSelect(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoGetValue(value: TAbstractModel; q1: TDataSet): Boolean; override;
    function SetValue(value: TAbstractModel; q1: TDataSet): Boolean; override;
  published
    property TableName: string read FTableName write SetTableName;
  end;
  TproceduresDAO = class(TAbstractDBDAO)
  private
    FTableName: string;
  protected
    procedure SetTableName(value: string);
  public
    function DoInsert(value: TAbstractModel; q1: TDataSet): Boolean; override;
    function DoUpdate(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoDelete(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoSelect(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoGetValue(value: TAbstractModel; q1: TDataSet): Boolean; override;
    function SetValue(value: TAbstractModel; q1: TDataSet): Boolean; override;
  published
    property TableName: string read FTableName write SetTableName;
  end;

  TFunctionsDAO = class(TAbstractDBDAO)
  private
    FTableName: string;
  protected
    procedure SetTableName(value: string);
  public
    function DoInsert(value: TAbstractModel; q1: TDataSet): Boolean; override;
    function DoUpdate(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoDelete(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoSelect(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean; override;
    function DoGetValue(value: TAbstractModel; q1: TDataSet): Boolean; override;
    function SetValue(value: TAbstractModel; q1: TDataSet): Boolean; override;
  published
    property TableName: string read FTableName write SetTableName;
  end;

var
  tablesDAO: TtablesDAO;
  columnsDAO: TcolumnsDAO;
  indexesDAO: TindexesDAO;
  frKeysDAO: TfrKeysDAO;
  systypesxDAO: TsystypesxDAO;
  usertypesDAO: TusertypesDAO;
  defaultsDAO: TdefaultsDAO;
  trigersDAO: TtrigersDAO;
  viewsDAO: TviewsDAO;
  proceduresDAO: TproceduresDAO;
  functionsDAO: TfunctionsDAO;

implementation

procedure TtablesDAO.SetTableName(value: string);
begin
  FTableName := value
end;

function TtablesDAO.DoInsert(value: TAbstractModel; q1: TDataSet): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      SQL.add('Insert Into tables');
      SQL.add('(seq,name,comments)');
      SQL.Add(' values( :seq,:name,:comments,:browsetype)');
      SetParamValue('seq', (value as TAbstracttables).seq);
      SetParamValue('name', (value as TAbstracttables).name);
      SetParamValue('comments', (value as TAbstracttables).comments);
      SetParamValue('browsetype', (value as TAbstracttables).browsetype);
//      SQL.Add('select SCOPE_IDENTITY() as id');
      Self.OpenAndReturnID(qp, 'id');
      Open;
      (value as TAbstracttables).id := FieldByName('id').AsInteger;
      result := true;
    end;
  finally
    qp.free;
  end;
end;

function TtablesDAO.DoUpdate(value: TAbstractModel; q1: TDataSet; Conditions: string = ''): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      SQL.Add('Update tables  set ');
      SQL.add('seq=:seq,name=:name,comments=:comments ,:browsetype');
      if (conditions = '') then
      begin
        SQL.Add(' where id=:id');
        SetParamValue('id', (value as TAbstracttables).id);
      end else
      begin
        SQL.ADD('where ' + conditions);
      end;
      SetParamValue('seq', (value as TAbstracttables).seq);
      SetParamValue('name', (value as TAbstracttables).name);
      SetParamValue('comments', (value as TAbstracttables).comments);
      SetParamValue('browsetype', (value as TAbstracttables).browsetype);

      ExecSQL;
      result := True;
    end;
  finally
    qp.free;
  end;
end;

function TtablesDAO.DoDelete(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      if (conditions = '') then
      begin
        SQL.Add('Delete from tables where id=:id');
        SetParamValue('id', (value as TAbstracttables).id);
      end else
        SQL.Add('Delete from tables where  ' + conditions);
      ExecSQL;
      result := true;
    end;
  finally
    qp.free;
  end;
end;

function TtablesDAO.DoSelect(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean;
var
  s1: string;
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      s1 := 'Select * from tables  ';
      if (conditions = '') then
      begin
        s1 := s1 + ' where id=:id';
        SQL.Add(s1);
        SetParamValue('id', (value as TAbstracttables).id);
      end else
      begin
        s1 := s1 + ' where ' + conditions;
        SQL.Add(s1);
      end;
      Open;
      result := True;
    end;
  finally
    qp.free;
  end;
end;

function TtablesDAO.DoGetValue(value: TAbstractModel; q1: TDataSet): Boolean;
var
  s1: string;
begin
  with q1 do
  begin
    (value as TAbstracttables).id := FieldByName('id').AsInteger;
    (value as TAbstracttables).seq := FieldByName('seq').AsInteger;
    (value as TAbstracttables).name := Trim(FieldByName('name').AsString);
    (value as TAbstracttables).comments := Trim(FieldByName('comments').AsString);
    (value as TAbstracttables).browsetype := Trim(FieldByName('browsetype').AsString);
    (value as TAbstracttables).idstr := Trim(FieldByName('idstr').AsString);
    (value as TAbstracttables).namestr := Trim(FieldByName('namestr').AsString);
    (value as TAbstracttables).codestr := Trim(FieldByName('codestr').AsString);

  end;

end;

function TtablesDAO.SetValue(value: TAbstractModel; q1: TDataSet): Boolean;
var
  s1: string;
begin
  with q1 do
  begin
    FieldByName('seq').AsInteger := (value as TAbstracttables).seq;
    FieldByName('name').AsString := (value as TAbstracttables).name;
    FieldByName('comments').AsString := (value as TAbstracttables).comments;
    FieldByName('browsetype').AsString := (value as TAbstracttables).browsetype;
    FieldByName('idstr').AsString := (value as TAbstracttables).idstr;
    FieldByName('namestr').AsString:= (value as TAbstracttables).namestr;
    FieldByName('codestr').AsString:= (value as TAbstracttables).codestr;

  end;
end;

procedure TcolumnsDAO.SetTableName(value: string);
begin
  FTableName := value
end;

function TcolumnsDAO.DoInsert(value: TAbstractModel; q1: TDataSet): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      SQL.add('Insert Into columns');
      SQL.add('(table_id,name,datatype,clength,cprecision,un');
      SQL.add('nn,Ai,Pk,cdefault,showname,');
      SQL.add('width,edittype,visible,comments,corder)');
      SQL.add(' values( :table_id,:name,:datatype,:clength,:cprecision,');
      SQL.add(':nn,:Ai,:Pk,:cdefault,:showname,');
      SQL.add(':width,:edittype,:visible,:comments,:corder)');
      SetParamValue('table_id', (value as TAbstractcolumns).table_id);
      SetParamValue('name', (value as TAbstractcolumns).name);
      SetParamValue('datatype', (value as TAbstractcolumns).datatype);
      SetParamValue('clength', (value as TAbstractcolumns).clength);
      SetParamValue('cprecision', (value as TAbstractcolumns).cprecision);
      SetParamValue('un', (value as TAbstractcolumns).un);      
      SetParamValue('nn', (value as TAbstractcolumns).nn);
      SetParamValue('Ai', (value as TAbstractcolumns).Ai);
      SetParamValue('Pk', (value as TAbstractcolumns).Pk);
      SetParamValue('cdefault', (value as TAbstractcolumns).cdefault);
      SetParamValue('showname', (value as TAbstractcolumns).showname);
      SetParamValue('width', (value as TAbstractcolumns).width);
      SetParamValue('edittype', (value as TAbstractcolumns).edittype);
      SetParamValue('visible', (value as TAbstractcolumns).visible);
      SetParamValue('comments', (value as TAbstractcolumns).comments);
      SetParamValue('corder', (value as TAbstractcolumns).corder);
      SQL.Add('select SCOPE_IDENTITY() as id');
      Open;
      (value as TAbstractcolumns).id := FieldByName('id').AsInteger;
      result := true;
    end;
  finally
    qp.free;
  end;
end;

function TcolumnsDAO.DoUpdate(value: TAbstractModel; q1: TDataSet; Conditions: string = ''): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      SQL.Add('Update columns  set ');
      SQL.add('table_id=:table_id,name=:name,datatype=:datatype,clength=:clength,cprecision=:cprecision,un=:un');
      SQL.add('nn=:nn,Ai=:Ai,Pk=:Pk,cdefault=:cdefault,showname=:showname,');
      SQL.add('width=:width,edittype=:edittype,visible=:visible,comments=:comments,corder=:corder ');
      if (conditions = '') then
      begin
        SQL.Add(' where id=:id');
        SetParamValue('id', (value as TAbstractcolumns).id);
      end else
      begin
        SQL.ADD('where ' + conditions);
      end;
      SetParamValue('table_id', (value as TAbstractcolumns).table_id);
      SetParamValue('name', (value as TAbstractcolumns).name);
      SetParamValue('datatype', (value as TAbstractcolumns).datatype);
      SetParamValue('clength', (value as TAbstractcolumns).clength);
      SetParamValue('cprecision', (value as TAbstractcolumns).cprecision);
      SetParamValue('un', (value as TAbstractcolumns).un);
      SetParamValue('nn', (value as TAbstractcolumns).nn);
      SetParamValue('Ai', (value as TAbstractcolumns).Ai);
      SetParamValue('Pk', (value as TAbstractcolumns).Pk);
      SetParamValue('cdefault', (value as TAbstractcolumns).cdefault);
      SetParamValue('showname', (value as TAbstractcolumns).showname);
      SetParamValue('width', (value as TAbstractcolumns).width);
      SetParamValue('edittype', (value as TAbstractcolumns).edittype);
      SetParamValue('visible', (value as TAbstractcolumns).visible);
      SetParamValue('comments', (value as TAbstractcolumns).comments);
      SetParamValue('corder', (value as TAbstractcolumns).corder);
      ExecSQL;
      result := True;
    end;
  finally
    qp.free;
  end;
end;

function TcolumnsDAO.DoDelete(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      if (conditions = '') then
      begin
        SQL.Add('Delete from columns where id=:id');
        SetParamValue('id', (value as TAbstractcolumns).id);
      end else
        SQL.Add('Delete from columns where  ' + conditions);
      ExecSQL;
      result := true;
    end;
  finally
    qp.free;
  end;
end;

function TcolumnsDAO.DoSelect(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean;
var
  s1: string;
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      s1 := 'Select * from columns  ';
      if (conditions = '') then
      begin
        s1 := s1 + ' where id=:id';
        SQL.Add(s1);
        SetParamValue('id', (value as TAbstractcolumns).id);
      end else
      begin
        s1 := s1 + ' where ' + conditions;
        SQL.Add(s1);
      end;
      Open;
      result := True;
    end;
  finally
    qp.free;
  end;
end;

function TcolumnsDAO.DoGetValue(value: TAbstractModel; q1: TDataSet): Boolean;
var
  s1: string;
begin
  with q1 do
  begin
    (value as TAbstractcolumns).id := FieldByName('id').AsInteger;
    (value as TAbstractcolumns).corder := FieldByName('corder').AsInteger;
    (value as TAbstractcolumns).table_id := FieldByName('table_id').AsInteger;
    (value as TAbstractcolumns).name := Trim(FieldByName('name').AsString);
    (value as TAbstractcolumns).datatype := Trim(FieldByName('datatype').AsString);
    (value as TAbstractcolumns).clength := FieldByName('clength').AsInteger;
    (value as TAbstractcolumns).cprecision := FieldByName('cprecision').AsInteger;
    (value as TAbstractcolumns).un := FieldByName('un').AsBoolean;
    (value as TAbstractcolumns).nn := FieldByName('nn').AsBoolean;
    (value as TAbstractcolumns).Ai := FieldByName('Ai').AsBoolean;
    (value as TAbstractcolumns).Pk := FieldByName('Pk').AsBoolean;
    (value as TAbstractcolumns).cdefault := Trim(FieldByName('cdefault').AsString);
    (value as TAbstractcolumns).showname := Trim(FieldByName('showname').AsString);
    (value as TAbstractcolumns).width := FieldByName('width').AsInteger;
    (value as TAbstractcolumns).edittype := Trim(FieldByName('edittype').AsString);
    (value as TAbstractcolumns).visible := FieldByName('visible').AsBoolean;
    (value as TAbstractcolumns).comments := Trim(FieldByName('comments').AsString);

    (value as TAbstractcolumns).Editable := FieldByName('Editable').AsBoolean;
    (value as TAbstractcolumns).SourceTable := Trim(FieldByName('SourceTable').AsString);
    (value as TAbstractcolumns).SourceField := Trim(FieldByName('SourceField').AsString);

  end;
end;

function TcolumnsDAO.SetValue(value: TAbstractModel; q1: TDataSet): Boolean;
var
  s1: string;
begin
  with q1 do
  begin
    FieldByName('corder').AsInteger := (value as TAbstractcolumns).corder;
    FieldByName('table_id').AsInteger := (value as TAbstractcolumns).table_id;
    FieldByName('name').AsString := (value as TAbstractcolumns).name;
    FieldByName('datatype').AsString := (value as TAbstractcolumns).datatype;
    FieldByName('clength').AsInteger := (value as TAbstractcolumns).clength;
    FieldByName('cprecision').AsInteger := (value as TAbstractcolumns).cprecision;
    FieldByName('un').AsBoolean := (value as TAbstractcolumns).un;
    FieldByName('nn').AsBoolean := (value as TAbstractcolumns).nn;
    FieldByName('Ai').AsBoolean := (value as TAbstractcolumns).Ai;
    FieldByName('Pk').AsBoolean := (value as TAbstractcolumns).Pk;
    FieldByName('cdefault').AsString := (value as TAbstractcolumns).cdefault;
    FieldByName('showname').AsString := (value as TAbstractcolumns).showname;
    FieldByName('width').AsInteger := (value as TAbstractcolumns).width;
    FieldByName('edittype').AsString := (value as TAbstractcolumns).edittype;
    FieldByName('visible').AsBoolean := (value as TAbstractcolumns).visible;
    FieldByName('comments').AsString := (value as TAbstractcolumns).comments;
    FieldByName('Editable').AsBoolean := (value as TAbstractcolumns).Editable;
    FieldByName('SourceTable').AsString := (value as TAbstractcolumns).SourceTable;
    FieldByName('SourceField').AsString := (value as TAbstractcolumns).SourceField;


  end;
end;

procedure TindexesDAO.SetTableName(value: string);
begin
  FTableName := value
end;

function TindexesDAO.DoInsert(value: TAbstractModel; q1: TDataSet): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      SQL.add('Insert Into indexes');
      SQL.add('(table_id,name,Indextype,column_id,column_seq,');
      SQL.add('corder,comments)');
      SQL.add(' values( :table_id,:name,:Indextype,:column_id,:column_seq,');
      SQL.Add(':corder,:comments)');
      SetParamValue('table_id', (value as TAbstractindexes).table_id);
      SetParamValue('name', (value as TAbstractindexes).name);
      SetParamValue('Indextype', (value as TAbstractindexes).Indextype);
      SetParamValue('column_id', (value as TAbstractindexes).column_id);
      SetParamValue('column_seq', (value as TAbstractindexes).column_seq);
      SetParamValue('corder', (value as TAbstractindexes).corder);
      SetParamValue('comments', (value as TAbstractindexes).comments);
      SQL.Add('select SCOPE_IDENTITY() as id');
      Open;
      (value as TAbstractindexes).id := FieldByName('id').AsInteger;
      result := true;
    end;
  finally
    qp.free;
  end;
end;

function TindexesDAO.DoUpdate(value: TAbstractModel; q1: TDataSet; Conditions: string = ''): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      SQL.Add('Update indexes  set ');
      SQL.add('table_id=:table_id,name=:name,Indextype=:Indextype,column_id=:column_id,column_seq=:column_seq,');
      SQL.add('corder=:corder,comments=:comments ');
      if (conditions = '') then
      begin
        SQL.Add(' where id=:id');
        SetParamValue('id', (value as TAbstractindexes).id);
      end else
      begin
        SQL.ADD('where ' + conditions);
      end;
      SetParamValue('table_id', (value as TAbstractindexes).table_id);
      SetParamValue('name', (value as TAbstractindexes).name);
      SetParamValue('Indextype', (value as TAbstractindexes).Indextype);
      SetParamValue('column_id', (value as TAbstractindexes).column_id);
      SetParamValue('column_seq', (value as TAbstractindexes).column_seq);
      SetParamValue('corder', (value as TAbstractindexes).corder);
      SetParamValue('comments', (value as TAbstractindexes).comments);
      ExecSQL;
      result := True;
    end;
  finally
    qp.free;
  end;
end;

function TindexesDAO.DoDelete(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      if (conditions = '') then
      begin
        SQL.Add('Delete from indexes where id=:id');
        SetParamValue('id', (value as TAbstractindexes).id);
      end else
        SQL.Add('Delete from indexes where  ' + conditions);
      ExecSQL;
      result := true;
    end;
  finally
    qp.free;
  end;
end;

function TindexesDAO.DoSelect(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean;
var
  s1: string;
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      s1 := 'Select * from indexes  ';
      if (conditions = '') then
      begin
        s1 := s1 + ' where id=:id';
        SQL.Add(s1);
        SetParamValue('id', (value as TAbstractindexes).id);
      end else
      begin
        s1 := s1 + ' where ' + conditions;
        SQL.Add(s1);
      end;
      Open;
      result := True;
    end;
  finally
    qp.free;
  end;
end;

function TindexesDAO.DoGetValue(value: TAbstractModel; q1: TDataSet): Boolean;
var
  s1: string;
begin
  with q1 do
  begin
    (value as TAbstractindexes).id := FieldByName('id').AsInteger;
    (value as TAbstractindexes).table_id := FieldByName('table_id').AsInteger;
    (value as TAbstractindexes).name := Trim(FieldByName('name').AsString);
    (value as TAbstractindexes).Indextype := Trim(FieldByName('Indextype').AsString);
    (value as TAbstractindexes).column_id := FieldByName('column_id').AsInteger;
    (value as TAbstractindexes).column_seq := FieldByName('column_seq').AsInteger;
    (value as TAbstractindexes).corder := FieldByName('corder').AsInteger;
    (value as TAbstractindexes).comments := Trim(FieldByName('comments').AsString);
  end;
end;

function TindexesDAO.SetValue(value: TAbstractModel; q1: TDataSet): Boolean;
var
  s1: string;
begin
  with q1 do
  begin
    FieldByName('table_id').AsInteger := (value as TAbstractindexes).table_id;
    FieldByName('name').AsString := (value as TAbstractindexes).name;
    FieldByName('Indextype').AsString := (value as TAbstractindexes).Indextype;
    FieldByName('column_id').AsInteger := (value as TAbstractindexes).column_id;
    FieldByName('column_seq').AsInteger := (value as TAbstractindexes).column_seq;
    FieldByName('corder').AsInteger := (value as TAbstractindexes).corder;
    FieldByName('comments').AsString := (value as TAbstractindexes).comments;
  end;
end;

procedure TfrKeysDAO.SetTableName(value: string);
begin
  FTableName := value
end;

function TfrKeysDAO.DoInsert(value: TAbstractModel; q1: TDataSet): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      SQL.add('Insert Into frKeys');
      SQL.add('(table_id,name,column_id,refer_table_id,refer_column_id,');
      SQL.add('comments,subtable)');
      SQL.add(' values( :table_id,:name,:column_id,:refer_table_id,:refer_column_id,');
      SQL.Add(':comments,:subtable)');
      SetParamValue('table_id', (value as TAbstractfrKeys).table_id);
      SetParamValue('name', (value as TAbstractfrKeys).name);
      SetParamValue('column_id', (value as TAbstractfrKeys).column_id);
      SetParamValue('refer_table_id', (value as TAbstractfrKeys).refer_table_id);
      SetParamValue('refer_column_id', (value as TAbstractfrKeys).refer_column_id);
      SetParamValue('comments', (value as TAbstractfrKeys).comments);
      SetParamValue('subtable', (value as TAbstractfrKeys).subtable);
      SQL.Add('select SCOPE_IDENTITY() as id');
      Open;
      (value as TAbstractfrKeys).id := FieldByName('id').AsInteger;
      result := true;
    end;
  finally
    qp.free;
  end;
end;

function TfrKeysDAO.DoUpdate(value: TAbstractModel; q1: TDataSet; Conditions: string = ''): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      SQL.Add('Update frKeys  set ');
      SQL.add('table_id=:table_id,name=:name,column_id=:column_id,refer_table_id=:refer_table_id,refer_column_id=:refer_column_id,');
      SQL.add('comments=:comments,subtable=:subtable ');
      if (conditions = '') then
      begin
        SQL.Add(' where id=:id');
        SetParamValue('id', (value as TAbstractfrKeys).id);
      end else
      begin
        SQL.ADD('where ' + conditions);
      end;
      SetParamValue('table_id', (value as TAbstractfrKeys).table_id);
      SetParamValue('name', (value as TAbstractfrKeys).name);
      SetParamValue('column_id', (value as TAbstractfrKeys).column_id);
      SetParamValue('refer_table_id', (value as TAbstractfrKeys).refer_table_id);
      SetParamValue('refer_column_id', (value as TAbstractfrKeys).refer_column_id);
      SetParamValue('comments', (value as TAbstractfrKeys).comments);
      SetParamValue('subtable', (value as TAbstractfrKeys).subtable);
      ExecSQL;
      result := True;
    end;
  finally
    qp.free;
  end;
end;

function TfrKeysDAO.DoDelete(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      if (conditions = '') then
      begin
        SQL.Add('Delete from frKeys where id=:id');
        SetParamValue('id', (value as TAbstractfrKeys).id);
      end else
        SQL.Add('Delete from frKeys where  ' + conditions);
      ExecSQL;
      result := true;
    end;
  finally
    qp.free;
  end;
end;

function TfrKeysDAO.DoSelect(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean;
var
  s1: string;
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      s1 := 'Select * from frKeys  ';
      if (conditions = '') then
      begin
        s1 := s1 + ' where id=:id';
        SQL.Add(s1);
        SetParamValue('id', (value as TAbstractfrKeys).id);
      end else
      begin
        s1 := s1 + ' where ' + conditions;
        SQL.Add(s1);
      end;
      Open;
      result := True;
    end;
  finally
    qp.free;
  end;
end;

function TfrKeysDAO.DoGetValue(value: TAbstractModel; q1: TDataSet): Boolean;
var
  s1: string;
begin
  with q1 do
  begin
    (value as TAbstractfrKeys).id := FieldByName('id').AsInteger;
    (value as TAbstractfrKeys).table_id := FieldByName('table_id').AsInteger;
    (value as TAbstractfrKeys).name := Trim(FieldByName('name').AsString);
    (value as TAbstractfrKeys).column_id := FieldByName('column_id').AsInteger;
    (value as TAbstractfrKeys).refer_table_id := FieldByName('refer_table_id').AsInteger;
    (value as TAbstractfrKeys).refer_column_id := FieldByName('refer_column_id').AsInteger;
    (value as TAbstractfrKeys).comments := Trim(FieldByName('comments').AsString);
    (value as TAbstractfrKeys).subtable := FieldByName('subtable').AsBoolean;
  end;
end;

function TfrKeysDAO.SetValue(value: TAbstractModel; q1: TDataSet): Boolean;
var
  s1: string;
begin
  with q1 do
  begin
    FieldByName('table_id').AsInteger := (value as TAbstractfrKeys).table_id;
    FieldByName('name').AsString := (value as TAbstractfrKeys).name;
    FieldByName('column_id').AsInteger := (value as TAbstractfrKeys).column_id;
    FieldByName('refer_table_id').AsInteger := (value as TAbstractfrKeys).refer_table_id;
    FieldByName('refer_column_id').AsInteger := (value as TAbstractfrKeys).refer_column_id;
    FieldByName('comments').AsString := (value as TAbstractfrKeys).comments;
    FieldByName('subtable').AsBoolean := (value as TAbstractfrKeys).subtable;
  end;
end;

procedure TsystypesxDAO.SetTableName(value: string);
begin
  FTableName := value
end;

function TsystypesxDAO.DoInsert(value: TAbstractModel; q1: TDataSet): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      SQL.add('Insert Into systypesx');
      SQL.add('(xtype,name)');
      SQL.Add(' values( :xtype,:name)');
      SetParamValue('xtype', (value as TAbstractsystypesx).xtype);
      SetParamValue('name', (value as TAbstractsystypesx).name);
      ExecSQL;
      result := true;
    end;
  finally
    qp.free;
  end;
end;

function TsystypesxDAO.DoUpdate(value: TAbstractModel; q1: TDataSet; Conditions: string = ''): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      SQL.Add('Update systypesx  set ');
      SQL.add('xtype=:xtype,name=:name ');
      if (conditions = '') then
      begin
        SQL.Add(' where xtype=:xtype');
        SetParamValue('xtype', (value as TAbstractsystypesx).xtype);
      end else
      begin
        SQL.ADD('where ' + conditions);
      end;
      SetParamValue('xtype', (value as TAbstractsystypesx).xtype);
      SetParamValue('name', (value as TAbstractsystypesx).name);
      ExecSQL;
      result := True;
    end;
  finally
    qp.free;
  end;
end;

function TsystypesxDAO.DoDelete(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      if (conditions = '') then
      begin
        SQL.Add('Delete from systypesx where xtype=:xtype');
        SetParamValue('xtype', (value as TAbstractsystypesx).xtype);
      end else
        SQL.Add('Delete from systypesx where  ' + conditions);
      ExecSQL;
      result := true;
    end;
  finally
    qp.free;
  end;
end;

function TsystypesxDAO.DoSelect(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean;
var
  s1: string;
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      s1 := 'Select * from systypesx  ';
      if (conditions = '') then
      begin
        s1 := s1 + ' where xtype=:xtype';
        SQL.Add(s1);
        SetParamValue('xtype', (value as TAbstractsystypesx).xtype);
      end else
      begin
        s1 := s1 + ' where ' + conditions;
        SQL.Add(s1);
      end;
      Open;
      result := True;
    end;
  finally
    qp.free;
  end;
end;

function TsystypesxDAO.DoGetValue(value: TAbstractModel; q1: TDataSet): Boolean;
var
  s1: string;
begin
  with q1 do
  begin
    (value as TAbstractsystypesx).xtype := FieldByName('xtype').AsInteger;
    (value as TAbstractsystypesx).name := Trim(FieldByName('name').AsString);
  end;
end;

function TsystypesxDAO.SetValue(value: TAbstractModel; q1: TDataSet): Boolean;
var
  s1: string;
begin
  with q1 do
  begin
    FieldByName('xtype').AsInteger := (value as TAbstractsystypesx).xtype;
    FieldByName('name').AsString := (value as TAbstractsystypesx).name;
  end;
end;

procedure TusertypesDAO.SetTableName(value: string);
begin
  FTableName := value
end;

function TusertypesDAO.DoInsert(value: TAbstractModel; q1: TDataSet): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      SQL.add('Insert Into usertypes');
      SQL.add('(name,xtype,tdefault,allownulls,prec,');
      SQL.add('scale)');
      SQL.add(' values( :name,:xtype,:tdefault,:allownulls,:prec,');
      SQL.Add(':scale)');
      SetParamValue('name', (value as TAbstractusertypes).name);
      SetParamValue('xtype', (value as TAbstractusertypes).xtype);
      SetParamValue('tdefault', (value as TAbstractusertypes).tdefault);
      SetParamValue('allownulls', (value as TAbstractusertypes).allownulls);
      SetParamValue('prec', (value as TAbstractusertypes).prec);
      SetParamValue('scale', (value as TAbstractusertypes).scale);
      SQL.Add('select SCOPE_IDENTITY() as id');
      Open;
      (value as TAbstractusertypes).id := FieldByName('id').AsInteger;
      result := true;
    end;
  finally
    qp.free;
  end;
end;

function TusertypesDAO.DoUpdate(value: TAbstractModel; q1: TDataSet; Conditions: string = ''): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      SQL.Add('Update usertypes  set ');
      SQL.add('name=:name,xtype=:xtype,tdefault=:tdefault,allownulls=:allownulls,prec=:prec,');
      SQL.add('scale=:scale ');
      if (conditions = '') then
      begin
        SQL.Add(' where id=:id');
        SetParamValue('id', (value as TAbstractusertypes).id);
      end else
      begin
        SQL.ADD('where ' + conditions);
      end;
      SetParamValue('name', (value as TAbstractusertypes).name);
      SetParamValue('xtype', (value as TAbstractusertypes).xtype);
      SetParamValue('tdefault', (value as TAbstractusertypes).tdefault);
      SetParamValue('allownulls', (value as TAbstractusertypes).allownulls);
      SetParamValue('prec', (value as TAbstractusertypes).prec);
      SetParamValue('scale', (value as TAbstractusertypes).scale);
      ExecSQL;
      result := True;
    end;
  finally
    qp.free;
  end;
end;

function TusertypesDAO.DoDelete(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      if (conditions = '') then
      begin
        SQL.Add('Delete from usertypes where id=:id');
        SetParamValue('id', (value as TAbstractusertypes).id);
      end else
        SQL.Add('Delete from usertypes where  ' + conditions);
      ExecSQL;
      result := true;
    end;
  finally
    qp.free;
  end;
end;

function TusertypesDAO.DoSelect(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean;
var
  s1: string;
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      s1 := 'Select * from usertypes  ';
      if (conditions = '') then
      begin
        s1 := s1 + ' where id=:id';
        SQL.Add(s1);
        SetParamValue('id', (value as TAbstractusertypes).id);
      end else
      begin
        s1 := s1 + ' where ' + conditions;
        SQL.Add(s1);
      end;
      Open;
      result := True;
    end;
  finally
    qp.free;
  end;
end;

function TusertypesDAO.DoGetValue(value: TAbstractModel; q1: TDataSet): Boolean;
var
  s1: string;
begin
  with q1 do
  begin
    (value as TAbstractusertypes).id := FieldByName('id').AsInteger;
    (value as TAbstractusertypes).name := Trim(FieldByName('name').AsString);
    (value as TAbstractusertypes).xtype := FieldByName('xtype').AsInteger;
    (value as TAbstractusertypes).tdefault := FieldByName('tdefault').AsInteger;
    (value as TAbstractusertypes).allownulls := FieldByName('allownulls').AsBoolean;
    (value as TAbstractusertypes).prec := FieldByName('prec').AsInteger;
    (value as TAbstractusertypes).scale := FieldByName('scale').AsInteger;
  end;
end;

function TusertypesDAO.SetValue(value: TAbstractModel; q1: TDataSet): Boolean;
var
  s1: string;
begin
  with q1 do
  begin
    FieldByName('name').AsString := (value as TAbstractusertypes).name;
    FieldByName('xtype').AsInteger := (value as TAbstractusertypes).xtype;
    FieldByName('tdefault').AsInteger := (value as TAbstractusertypes).tdefault;
    FieldByName('allownulls').AsBoolean := (value as TAbstractusertypes).allownulls;
    FieldByName('prec').AsInteger := (value as TAbstractusertypes).prec;
    FieldByName('scale').AsInteger := (value as TAbstractusertypes).scale;
  end;
end;

procedure TdefaultsDAO.SetTableName(value: string);
begin
  FTableName := value
end;

function TdefaultsDAO.DoInsert(value: TAbstractModel; q1: TDataSet): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      SQL.add('Insert Into defaults');
      SQL.add('(id,name,dtext)');
      SQL.Add(' values( :id,:name,:dtext)');
      SetParamValue('id', (value as TAbstractdefaults).id);
      SetParamValue('name', (value as TAbstractdefaults).name);
      SetParamValue('dtext', (value as TAbstractdefaults).dtext);
      ExecSQL;
      result := true;
    end;
  finally
    qp.free;
  end;
end;

function TdefaultsDAO.DoUpdate(value: TAbstractModel; q1: TDataSet; Conditions: string = ''): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      SQL.Add('Update defaults  set ');
      SQL.add('id=:id,name=:name,dtext=:dtext ');
      if (conditions = '') then
      begin
        SQL.Add(' where id=:id');
        SetParamValue('id', (value as TAbstractdefaults).id);
      end else
      begin
        SQL.ADD('where ' + conditions);
      end;
      SetParamValue('id', (value as TAbstractdefaults).id);
      SetParamValue('name', (value as TAbstractdefaults).name);
      SetParamValue('dtext', (value as TAbstractdefaults).dtext);
      ExecSQL;
      result := True;
    end;
  finally
    qp.free;
  end;
end;

function TdefaultsDAO.DoDelete(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      if (conditions = '') then
      begin
        SQL.Add('Delete from defaults where id=:id');
        SetParamValue('id', (value as TAbstractdefaults).id);
      end else
        SQL.Add('Delete from defaults where  ' + conditions);
      ExecSQL;
      result := true;
    end;
  finally
    qp.free;
  end;
end;

function TdefaultsDAO.DoSelect(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean;
var
  s1: string;
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      s1 := 'Select * from defaults  ';
      if (conditions = '') then
      begin
        s1 := s1 + ' where id=:id';
        SQL.Add(s1);
        SetParamValue('id', (value as TAbstractdefaults).id);
      end else
      begin
        s1 := s1 + ' where ' + conditions;
        SQL.Add(s1);
      end;
      Open;
      result := True;
    end;
  finally
    qp.free;
  end;
end;

function TdefaultsDAO.DoGetValue(value: TAbstractModel; q1: TDataSet): Boolean;
var
  s1: string;
begin
  with q1 do
  begin
    (value as TAbstractdefaults).id := FieldByName('id').AsInteger;
    (value as TAbstractdefaults).name := Trim(FieldByName('name').AsString);
    (value as TAbstractdefaults).dtext := FieldByName('dtext').AsVariant;
  end;
end;

function TdefaultsDAO.SetValue(value: TAbstractModel; q1: TDataSet): Boolean;
var
  s1: string;
begin
  with q1 do
  begin
    FieldByName('id').AsInteger := (value as TAbstractdefaults).id;
    FieldByName('name').AsString := (value as TAbstractdefaults).name;
    FieldByName('dtext').AsVariant := (value as TAbstractdefaults).dtext;
  end;
end;

procedure TtrigersDAO.SetTableName(value: string);
begin
  FTableName := value
end;

function TtrigersDAO.DoInsert(value: TAbstractModel; q1: TDataSet): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      SQL.add('Insert Into trigers');
      SQL.add('(id,name,table_id,dtext)');
      SQL.Add(' values( :id,:name,:table_id,:dtext)');
      SetParamValue('id', (value as TAbstracttrigers).id);
      SetParamValue('name', (value as TAbstracttrigers).name);
      SetParamValue('table_id', (value as TAbstracttrigers).table_id);
      SetParamValue('dtext', (value as TAbstracttrigers).dtext);
      ExecSQL;
      result := true;
    end;
  finally
    qp.free;
  end;
end;

function TtrigersDAO.DoUpdate(value: TAbstractModel; q1: TDataSet; Conditions: string = ''): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      SQL.Add('Update trigers  set ');
      SQL.add('id=:id,name=:name,table_id=:table_id,dtext=:dtext ');
      if (conditions = '') then
      begin
        SQL.Add(' where id=:id');
        SetParamValue('id', (value as TAbstracttrigers).id);
      end else
      begin
        SQL.ADD('where ' + conditions);
      end;
      SetParamValue('id', (value as TAbstracttrigers).id);
      SetParamValue('name', (value as TAbstracttrigers).name);
      SetParamValue('table_id', (value as TAbstracttrigers).table_id);
      SetParamValue('dtext', (value as TAbstracttrigers).dtext);
      ExecSQL;
      result := True;
    end;
  finally
    qp.free;
  end;
end;

function TtrigersDAO.DoDelete(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      if (conditions = '') then
      begin
        SQL.Add('Delete from trigers where id=:id');
        SetParamValue('id', (value as TAbstracttrigers).id);
      end else
        SQL.Add('Delete from trigers where  ' + conditions);
      ExecSQL;
      result := true;
    end;
  finally
    qp.free;
  end;
end;

function TtrigersDAO.DoSelect(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean;
var
  s1: string;
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      s1 := 'Select * from trigers  ';
      if (conditions = '') then
      begin
        s1 := s1 + ' where id=:id';
        SQL.Add(s1);
        SetParamValue('id', (value as TAbstracttrigers).id);
      end else
      begin
        s1 := s1 + ' where ' + conditions;
        SQL.Add(s1);
      end;
      Open;
      result := True;
    end;
  finally
    qp.free;
  end;
end;

function TtrigersDAO.DoGetValue(value: TAbstractModel; q1: TDataSet): Boolean;
var
  s1: string;
begin
  with q1 do
  begin
    (value as TAbstracttrigers).id := FieldByName('id').AsInteger;
    (value as TAbstracttrigers).name := Trim(FieldByName('name').AsString);
    (value as TAbstracttrigers).table_id := FieldByName('table_id').AsInteger;
    (value as TAbstracttrigers).dtext := FieldByName('dtext').AsVariant;
  end;
end;

function TtrigersDAO.SetValue(value: TAbstractModel; q1: TDataSet): Boolean;
var
  s1: string;
begin
  with q1 do
  begin
    FieldByName('id').AsInteger := (value as TAbstracttrigers).id;
    FieldByName('name').AsString := (value as TAbstracttrigers).name;
    FieldByName('table_id').AsInteger := (value as TAbstracttrigers).table_id;
    FieldByName('dtext').AsVariant := (value as TAbstracttrigers).dtext;
  end;
end;

procedure TviewsDAO.SetTableName(value: string);
begin
  FTableName := value
end;

function TviewsDAO.DoInsert(value: TAbstractModel; q1: TDataSet): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      SQL.add('Insert Into views');
      SQL.add('(id,name,dtext)');
      SQL.Add(' values( :id,:name,:dtext)');
      SetParamValue('id', (value as TAbstractviews).id);
      SetParamValue('name', (value as TAbstractviews).name);
      SetParamValue('dtext', (value as TAbstractviews).dtext);
      ExecSQL;
      result := true;
    end;
  finally
    qp.free;
  end;
end;

function TviewsDAO.DoUpdate(value: TAbstractModel; q1: TDataSet; Conditions: string = ''): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      SQL.Add('Update views  set ');
      SQL.add('id=:id,name=:name,dtext=:dtext ');
      if (conditions = '') then
      begin
        SQL.Add(' where id=:id');
        SetParamValue('id', (value as TAbstractviews).id);
      end else
      begin
        SQL.ADD('where ' + conditions);
      end;
      SetParamValue('id', (value as TAbstractviews).id);
      SetParamValue('name', (value as TAbstractviews).name);
      SetParamValue('dtext', (value as TAbstractviews).dtext);
      ExecSQL;
      result := True;
    end;
  finally
    qp.free;
  end;
end;

function TviewsDAO.DoDelete(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      if (conditions = '') then
      begin
        SQL.Add('Delete from views where id=:id');
        SetParamValue('id', (value as TAbstractviews).id);
      end else
        SQL.Add('Delete from views where  ' + conditions);
      ExecSQL;
      result := true;
    end;
  finally
    qp.free;
  end;
end;

function TviewsDAO.DoSelect(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean;
var
  s1: string;
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      s1 := 'Select * from views  ';
      if (conditions = '') then
      begin
        s1 := s1 + ' where id=:id';
        SQL.Add(s1);
        SetParamValue('id', (value as TAbstractviews).id);
      end else
      begin
        s1 := s1 + ' where ' + conditions;
        SQL.Add(s1);
      end;
      Open;
      result := True;
    end;
  finally
    qp.free;
  end;
end;

function TviewsDAO.DoGetValue(value: TAbstractModel; q1: TDataSet): Boolean;
var
  s1: string;
begin
  with q1 do
  begin
    (value as TAbstractviews).id := FieldByName('id').AsInteger;
    (value as TAbstractviews).name := Trim(FieldByName('name').AsString);
    (value as TAbstractviews).dtext := FieldByName('dtext').AsVariant;
  end;
end;

function TviewsDAO.SetValue(value: TAbstractModel; q1: TDataSet): Boolean;
var
  s1: string;
begin
  with q1 do
  begin
    FieldByName('id').AsInteger := (value as TAbstractviews).id;
    FieldByName('name').AsString := (value as TAbstractviews).name;
    FieldByName('dtext').AsVariant := (value as TAbstractviews).dtext;
  end;
end;

procedure TproceduresDAO.SetTableName(value: string);
begin
  FTableName := value
end;

function TproceduresDAO.DoInsert(value: TAbstractModel; q1: TDataSet): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      SQL.add('Insert Into procedures');
      SQL.add('(id,name,dtext)');
      SQL.Add(' values( :id,:name,:dtext)');
      SetParamValue('id', (value as TAbstractprocedures).id);
      SetParamValue('name', (value as TAbstractprocedures).name);
      SetParamValue('dtext', (value as TAbstractprocedures).dtext);
      ExecSQL;
      result := true;
    end;
  finally
    qp.free;
  end;
end;

function TproceduresDAO.DoUpdate(value: TAbstractModel; q1: TDataSet; Conditions: string = ''): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      SQL.Add('Update procedures  set ');
      SQL.add('id=:id,name=:name,dtext=:dtext ');
      if (conditions = '') then
      begin
        SQL.Add(' where id=:id');
        SetParamValue('id', (value as TAbstractprocedures).id);
      end else
      begin
        SQL.ADD('where ' + conditions);
      end;
      SetParamValue('id', (value as TAbstractprocedures).id);
      SetParamValue('name', (value as TAbstractprocedures).name);
      SetParamValue('dtext', (value as TAbstractprocedures).dtext);
      ExecSQL;
      result := True;
    end;
  finally
    qp.free;
  end;
end;

function TproceduresDAO.DoDelete(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      if (conditions = '') then
      begin
        SQL.Add('Delete from procedures where id=:id');
        SetParamValue('id', (value as TAbstractprocedures).id);
      end else
        SQL.Add('Delete from procedures where  ' + conditions);
      ExecSQL;
      result := true;
    end;
  finally
    qp.free;
  end;
end;

function TproceduresDAO.DoSelect(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean;
var
  s1: string;
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      s1 := 'Select * from procedures  ';
      if (conditions = '') then
      begin
        s1 := s1 + ' where id=:id';
        SQL.Add(s1);
        SetParamValue('id', (value as TAbstractprocedures).id);
      end else
      begin
        s1 := s1 + ' where ' + conditions;
        SQL.Add(s1);
      end;
      Open;
      result := True;
    end;
  finally
    qp.free;
  end;
end;

function TproceduresDAO.DoGetValue(value: TAbstractModel; q1: TDataSet): Boolean;
var
  s1: string;
begin
  with q1 do
  begin
    (value as TAbstractprocedures).id := FieldByName('id').AsInteger;
    (value as TAbstractprocedures).name := Trim(FieldByName('name').AsString);
    (value as TAbstractprocedures).dtext := FieldByName('dtext').AsVariant;
  end;
end;

function TproceduresDAO.SetValue(value: TAbstractModel; q1: TDataSet): Boolean;
var
  s1: string;
begin
  with q1 do
  begin
    FieldByName('id').AsInteger := (value as TAbstractprocedures).id;
    FieldByName('name').AsString := (value as TAbstractprocedures).name;
    FieldByName('dtext').AsVariant := (value as TAbstractprocedures).dtext;
  end;
end;
///

procedure TfunctionsDAO.SetTableName(value: string);
begin
  FTableName := value
end;

function TfunctionsDAO.DoInsert(value: TAbstractModel; q1: TDataSet): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      SQL.add('Insert Into Functions');
      SQL.add('(id,name,dtext)');
      SQL.Add(' values( :id,:name,:dtext)');
      SetParamValue('id', (value as TAbstractFunctions).id);
      SetParamValue('name', (value as TAbstractFunctions).name);
      SetParamValue('dtext', (value as TAbstractFunctions).dtext);
      ExecSQL;
      result := true;
    end;
  finally
    qp.free;
  end;
end;

function TfunctionsDAO.DoUpdate(value: TAbstractModel; q1: TDataSet; Conditions: string = ''): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      SQL.Add('Update functions  set ');
      SQL.add('id=:id,name=:name,dtext=:dtext ');
      if (conditions = '') then
      begin
        SQL.Add(' where id=:id');
        SetParamValue('id', (value as TAbstractFunctions).id);
      end else
      begin
        SQL.ADD('where ' + conditions);
      end;
      SetParamValue('id', (value as TAbstractFunctions).id);
      SetParamValue('name', (value as TAbstractFunctions).name);
      SetParamValue('dtext', (value as TAbstractFunctions).dtext);
      ExecSQL;
      result := True;
    end;
  finally
    qp.free;
  end;
end;

function TfunctionsDAO.DoDelete(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean;
var
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      if (conditions = '') then
      begin
        SQL.Add('Delete from functions where id=:id');
        SetParamValue('id', (value as TAbstractFunctions).id);
      end else
        SQL.Add('Delete from functions where  ' + conditions);
      ExecSQL;
      result := true;
    end;
  finally
    qp.free;
  end;
end;

function TfunctionsDAO.DoSelect(value: TAbstractModel; q1: TDataSet; conditions: string = ''): Boolean;
var
  s1: string;
  qp: TQueryProxy;
begin
  qp := TQueryProxy.Create;
  qp.dataset := q1;
  try
    with qp do
    begin
      close;
      SQL.Clear;
      s1 := 'Select * from functions  ';
      if (conditions = '') then
      begin
        s1 := s1 + ' where id=:id';
        SQL.Add(s1);
        SetParamValue('id', (value as TAbstractFunctions).id);
      end else
      begin
        s1 := s1 + ' where ' + conditions;
        SQL.Add(s1);
      end;
      Open;
      result := True;
    end;
  finally
    qp.free;
  end;
end;

function TfunctionsDAO.DoGetValue(value: TAbstractModel; q1: TDataSet): Boolean;
var
  s1: string;
begin
  with q1 do
  begin
    (value as TAbstractFunctions).id := FieldByName('id').AsInteger;
    (value as TAbstractFunctions).name := Trim(FieldByName('name').AsString);
    (value as TAbstractFunctions).dtext := FieldByName('dtext').AsVariant;
  end;
end;

function TfunctionsDAO.SetValue(value: TAbstractModel; q1: TDataSet): Boolean;
var
  s1: string;
begin
  with q1 do
  begin
    FieldByName('id').AsInteger := (value as TAbstractFunctions).id;
    FieldByName('name').AsString := (value as TAbstractFunctions).name;
    FieldByName('dtext').AsVariant := (value as TAbstractFunctions).dtext;
  end;
end;
initialization
  tablesDAO := TtablesDAO.Create;
  columnsDAO := TcolumnsDAO.Create;
  indexesDAO := TindexesDAO.Create;
  frKeysDAO := TfrKeysDAO.Create;
  systypesxDAO := TsystypesxDAO.Create;
  usertypesDAO := TusertypesDAO.Create;
  defaultsDAO := TdefaultsDAO.Create;
  trigersDAO := TtrigersDAO.Create;
  viewsDAO := TviewsDAO.Create;
  proceduresDAO := TproceduresDAO.Create;
  functionsDAO := TfunctionsDAO.Create;
end.

